package 力扣_简单题;

/**
 * @author 连安利
 * @version 1.0
 * @date 2021/3/31 18:33
 */
public class 字符串相加 {
    public String addStrings(String num1, String num2) {
        int p1 = num1.length()-1;
        int p2 = num2.length()-1;
        StringBuffer res = new StringBuffer("");
        int carry = 0;
        while (p1 >= 0 || p2 >= 0){
            int x;
            int y;
            if(p1 >=0 ){
                x = num1.charAt(p1) - '0';
            }
            else {
                x = 0;
            }
            if(p2 >= 0 ){
                y = num2.charAt(p2) - '0';
            }
            else {
                y = 0;
            }
            int temp = x + y +carry;
            carry = temp / 10 ;
            res.append(temp % 10);
            p1--;
            p2--;
        }
        if (carry == 1){
            res.append(1);
        }
        return res.reverse().toString();
    }
}
